package com.smartwebee.android.blespp.hospital;

import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.smartwebee.android.blespp.R;

import java.util.List;

/**
 * Created by steward on 2018/6/27.
 */

public class HospitalScanAdapter extends HospitalBaseAdapter<BluetoothDevice> {
    public HospitalScanAdapter(Context context, List<BluetoothDevice> datas) {
        super(context, datas);
    }

    @Override
    protected View initView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.adapter_hospital_scan, parent, false);
            viewHolder = new ViewHolder();
            viewHolder.tvName = (TextView)convertView.findViewById(R.id.tv_name);
            viewHolder.tvMac = (TextView)convertView.findViewById(R.id.tv_mac);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        BluetoothDevice device = getItem(position);
        viewHolder.tvName.setText(device.getName());
        viewHolder.tvMac.setText(device.getAddress());
        return convertView;
    }

    public class ViewHolder {
        public TextView tvName;
        public TextView tvMac;
    }

    @Override
    public void addItem(BluetoothDevice data) {
        if (!datas.contains(data)) {
            this.datas.add(data);
            notifyDataSetChanged();
        }
    }
}
